package com.adopapa.ethexplorer.domain;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonFormat;

@Entity
@Table(name = "TX_INFO")
public class TransactionInfo extends BaseUuidEntity {

	private static final long serialVersionUID = 7870161598714291305L;

	@Column(name = "block_hash")
	private String blockHash;
	@Column(name = "block_number")
	private Long blockNumber;
	@Column(name = "hash")
	private String hash;
	@Column(name = "from_addr")
	private String from;
	@Column(name = "to_addr")
	private String to;
	@Column(name = "tx_index")
	private Long txIndex;
	@Column(name = "value")
	private Long value;
	@Column(name = "nonce")
	private Long nonce;
	@Column(name = "time_stamp")
	private Long timestamp;
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
	@Column(name = "create_time")
	private Instant createTime;

	///////////////////////////////////////////
	public String getBlockHash() {
		return blockHash;
	}

	public void setBlockHash(String blockHash) {
		this.blockHash = blockHash;
	}

	public TransactionInfo blockHash(String blockHash) {
		this.blockHash = blockHash;
		return this;
	}

	public Long getBlockNumber() {
		return blockNumber;
	}

	public void setBlockNumber(Long blockNumber) {
		this.blockNumber = blockNumber;
	}

	public TransactionInfo blockNumber(Long blockNumber) {
		this.blockNumber = blockNumber;
		return this;
	}

	public String getHash() {
		return hash;
	}

	public void setHash(String hash) {
		this.hash = hash;
	}

	public TransactionInfo hash(String hash) {
		this.hash = hash;
		return this;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public TransactionInfo from(String from) {
		this.from = from;
		return this;
	}

	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}

	public TransactionInfo to(String to) {
		this.to = to;
		return this;
	}

	public Long getTxIndex() {
		return txIndex;
	}

	public void setTxIndex(Long txIndex) {
		this.txIndex = txIndex;
	}

	public TransactionInfo txIndex(Long txIndex) {
		this.txIndex = txIndex;
		return this;
	}

	public Long getValue() {
		return value;
	}

	public void setValue(Long value) {
		this.value = value;
	}

	public TransactionInfo value(Long value) {
		this.value = value;
		return this;
	}

	public Long getNonce() {
		return nonce;
	}

	public void setNonce(Long nonce) {
		this.nonce = nonce;
	}

	public TransactionInfo nonce(Long nonce) {
		this.nonce = nonce;
		return this;
	}

	public Long getTimestampRaw() {
		return timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	public TransactionInfo timestamp(Long timestamp) {
		this.timestamp = timestamp;
		return this;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
	public LocalDateTime getTimestamp() {
		return LocalDateTime.ofEpochSecond(this.timestamp, 0, ZoneOffset.ofHours(8));
	}

	public Instant getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Instant createTime) {
		this.createTime = createTime;
	}

	public TransactionInfo createTime(Instant createTime) {
		this.createTime = createTime;
		return this;
	}

}
